package shiyan5;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class PersonSortable implements Comparable<PersonSortable>{
	private String name;
	private int age;
	
	public PersonSortable(String name, int age) {
		this.name = name;
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return name + "-" + age ;
	}
	


	@Override
	public int compareTo(PersonSortable p) {
		int x=this.name.compareTo(p.getName());
		if(x==0){
			if(this.age>p.getAge())
				return 1;
			else if(this.age<p.getAge())
				return -1;
			else 
				return 0;
		}
		else
			return x;
	}
	
}

public class Sy51 {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = Integer.parseInt(input.nextLine());
		List<PersonSortable> per=new ArrayList<PersonSortable>();
        for(int i=0;i<n;i++){
        	per.add(new PersonSortable(input.next(),input.nextInt()));
        }
        Collections.sort(per);
        for(PersonSortable person:per){
        	System.out.println(person);
        }
        System.out.println(Arrays.toString(PersonSortable.class.getInterfaces())); 
	}

}
